<!-- 平台日志 -->
<template>
  <div class="page-main">
    <CustomForm :formInline="form" @onSubmit="onSubmit" @resetTable="resetTable">
      <el-form-item label="姓名">
        <el-input v-model="form.user_name" placeholder="输入业务人员姓名"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.tel" placeholder="输入业务人员手机号"></el-input>
      </el-form-item>
    </CustomForm>
    <el-button type="primary" style="margin-bottom: 10px;" @click="toAddUser">添加业务人员</el-button>
    <el-table
      :data="list"
      style="width: 100%"
      height="640"
      v-loading="tableloading"
      border
      ref="multipleTable"
    >
      <el-table-column prop="id" label="ID" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="user_name" label="姓名" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="tel" label="手机号" align="center" :show-overflow-tooltip="true"></el-table-column>
      <!-- <el-table-column prop="level" label="等级" align="center" :show-overflow-tooltip="true"></el-table-column> -->
      <el-table-column prop="add_time" label="添加时间" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="form.page"
      :page-sizes="$pageSizeList"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    <el-dialog
      :title="!isEdit ? '添加业务人员' : '编辑业务人员'"
      :visible.sync="addUserDialog"
      :close-on-click-modal="false"
      width="30%"
      top="20vh"
    >
      <addUser v-if="addUserDialog" :isEdit="isEdit" :editForm="editForm" @refresh="resetTable" />
    </el-dialog>
  </div>
</template>
  
  <script>
import { getBusinessList } from "@/api/business.js";
import addUser from "./components/addUser.vue";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    addUser
  },
  data() {
    //这里存放数据
    return {
      form: {
        tel: "",
        user_name: "",
        page: 1,
        pageSize: 10
      },
      isEdit:false,
      list: [],
      total: 0,
      pickerData: [],
      tableloading: false,
      editForm:{},
      addUserDialog: false
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    async initial() {
      this.tableloading = true;
      let res = await getBusinessList(this.form);
      this.tableloading = false;
      if (res.code == 200) {
        this.list = res.data.data ? res.data.data : [];
        this.total = res.data.total ? res.data.total : 0;
      }
    },
    toAddUser() {
      this.isEdit = false;
      this.addUserDialog = true;
    },
    edit(row){
      this.isEdit = true;
      this.editForm = row;
      this.addUserDialog = true;
    },
    onSubmit() {
      this.form.page = 1;
      this.form.pageSize = 10;
      this.initial();
    },
    updateCode(row) {
      this.$confirm("确定要更新发送时间吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          //   let result = await updatePhoneCodeTime({
          //     id: row.id,
          //     tel: row.mobile
          //   });
          //   if (result.code == 200) {
          //     this.$message({
          //       type: "success",
          //       message: "更新成功!"
          //     });
          //     this.resetTable();
          //   }
        })
        .catch(() => {});
    },
    resetTable() {
      this.form = {
        tel: "",
        user_name: "",
        page: 1,
        pageSize: 10
      };
      this.addUserDialog = false;
      this.initial();
    },
    handleSizeChange(pageSize) {
      this.form.pageSize = pageSize;
      this.initial();
    },
    handleCurrentChange(page) {
      this.form.page = page;
      this.initial();
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.initial();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
  <style lang='scss' scoped>
//@import url(); 引入公共css类
::v-deep .el-pagination {
  margin-top: 20px;
}

::v-deep .el-table .el-table__cell {
  padding: 10px 0;
}
</style>